﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace Smart.Data
{
    /// <summary>
    /// 数据工具类
    /// </summary>
    public class DataUtils
    {
        /// <summary>
        /// 数据表转换成XMl字符串
        /// </summary>
        /// <param name="data">数据表</param>
        /// <param name="mode">转换模式，默认忽略数据格式</param>
        /// <returns></returns>
        public static string DataTableToXml(DataTable data, XmlWriteMode mode = XmlWriteMode.IgnoreSchema)
        {
            using (var ms = new System.IO.MemoryStream())
            {
                data.WriteXml(ms, mode);
                ms.Position = 0;
                return Encoding.UTF8.GetString(ms.ToArray());
            }
        }
    }
}
